package com.lovvyang.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lovvyang
 * @date 2020/6/10-22:42
 */
@WebServlet("/servletContext01")
public class ServletContext01 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ServletContext servletContext1 = request.getServletContext();
        ServletContext servletContext2 = this.getServletContext();
        //定义文件名称
        String file ="a.jpg";
        String mimeType = servletContext1.getMimeType(file);
        System.out.println(mimeType);
        Object bra = servletContext1.getAttribute("bra");
        System.out.println(bra);
    }
}
